package com.nbsaas.boot.data.data.entity;


import com.nbsaas.boot.code.annotation.CatalogClass;
import com.nbsaas.boot.code.annotation.FieldConvert;
import com.nbsaas.boot.code.annotation.FieldName;
import com.nbsaas.boot.code.annotation.FormAnnotation;
import com.nbsaas.boot.jpa.data.entity.CatalogEntity;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@CatalogClass
@org.hibernate.annotations.Table(appliesTo = "sys_common_query_catalog", comment = "查询分类")
@Data
@FormAnnotation(title = "查询分类")
@Entity
@Table(name = "sys_common_query_catalog")
public class QueryCatalog extends CatalogEntity {

    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private QueryCatalog parent;


    @OneToMany(fetch = FetchType.LAZY,mappedBy = "parent")
    private List<QueryCatalog> children;

    @Override
    public Serializable getParentId() {
        if (parent != null) {
            return parent.getId();
        }
        return null;
    }
}
